﻿using System;
using System.Threading.Tasks;
using Caliburn.Micro;
using RatingAuthor;

namespace SamizdatSearch
{
  public class LoadingDbViewModel : PropertyChangedBase
  {
    private readonly Action<SiDatabase> _done;
    
    public double Progress
    {
      get { return _progress; }
      set
      {
        if (_progress == value) return;
        _progress = value;
        NotifyOfPropertyChange(() => Progress);
      }
    }

    private double _progress;

    public LoadingDbViewModel(Action<SiDatabase> done)
    {
      _done = done;
    }

    public void OnLoaded()
    {
      Task.Factory.StartNew(() => _done(SiDatabase.LoadIfExists("База Данных СИ.bin", p => Progress = p)));
    }
  }
}